/*!
 * \file MapaRepresentaciones.cpp
 *
 * \date Jul 29, 2014
 * \author correa
 */
#include "MapaRepresentaciones.h"

using namespace std;

void RowOfRepresentaciones::fill(int r, const VertexSet& g) {
	resize(g.capacity());

	int i;
	for (i = 0; i < r; i++)
		(*this)[i] = -1;
	(*this)[i++] = _nelem++;
	VertexSetIterator it = g.begin(r);
	for (; it != g.end(); ++it)
	{
		for (; i < *it; i++)
			(*this)[i] = -1;
		(*this)[i++] = _nelem++;
	}
	for (; i < g.capacity(); i++)
		(*this)[i] = -1;
}

MatrixOfRepresentaciones::MatrixOfRepresentaciones(Grafo& g) : vector<RowOfRepresentaciones>(g.getN()) {
	g.turnToComp();

	for (int i = 0; i < g.getN(); i++)
		vector<RowOfRepresentaciones>::operator [](i).fill(i, g.vecinos(i));

	g.turnToComp();
}

ArrayOfRepresentaciones::ArrayOfRepresentaciones(MatrixOfRepresentaciones& matrix) : vector<SubArrayOfRepresentaciones>(matrix.capacity()) {
	int j = 0;
	SubArrayOfRepresentaciones& row = operator [](0);
	row._row = &matrix[0];
	row._nhasta = 0;
	row._nelem = matrix[0].size();
	for (int i = 1; i < matrix.capacity(); i++) {
		SubArrayOfRepresentaciones& row = operator [](i);
		row._row = &matrix[i];
		row._nhasta = operator [](i-1)._nhasta+matrix[i-1].size();
		row._nelem = matrix[i].size();
	}
}
